<?php include('_init_.php'); ?>
<?php 
$GLOBALS['PAGE_ADDED_URL'] = 'working-edit.php';
if ( isset($_REQUEST['cat_id']) ) {
	$GLOBALS['PAGE_ADDED_URL'] .= '?cat_id='.$_REQUEST['cat_id'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../css/admin-body.css" rel="stylesheet" type="text/css" />
<link href="../css/admin-working.css" rel="stylesheet" type="text/css" />
<link href="../css/uploadifyb.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../js/swfobject.js"></script>
<script type="text/javascript" src="../js/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
// <![CDATA[
$(function(){
	$(".uploadifyupload").each(function(){
		
		var previous_img_id = $(this).attr('name');
		$(this).uploadify({
			'uploader': 'uploadify.swf',
			'cancelImg': 'cancel.png',
			'script': 'uploadify.php',
			'folder': 'files',
			'multi': false,
			'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
				'fileDesc':'Image Files',
			'auto': true,
			'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','name':$(this).attr('name'),'responsetype':'sizeinfo'},
			'displayData': 'speed',
			'onComplete':function(event,queueID,fileObj,response,data){
				var responseObj = eval("("+response+")");
				var fileName = responseObj.name;
				$('#img_'+previous_img_id).attr('src','../img/tmp/' + fileName);
				$('#img_'+previous_img_id).show();
				$('input[name=ajaxf_'+previous_img_id+']').val(fileName);
				
			},
			'onError':function(event,queueId,fileObj,errorObj){
				alert(errorObj);
			}
		});
	});
});
// ]]>
</script>
<script language="javascript" src="../js/rAlertb.js"></script>
<script language="javascript">
var global_uploaded_image = [];
function edit_toa(id) {
	global_uploaded_image = [];
	$('#PhotoList .img-add').remove();
	rAlert("working-photo-add.php" , null, "新增相片",810, 600);
}
function working_photo_add_uploaded_image(img_url)
{
	global_uploaded_image.push(img_url);
	$('#PhotoList').append('<ul class="img-add"><li class="photo-indexa"><img src="../img/tmp/'+img_url+'" width="300" height="200" /></li><li class="pl-1"><a href="#del">&nbsp;</a></li><li class="pl-1">&nbsp;</li></ul>');
}
function working_photo_add_uploaded_image_complete()
{
	rClose();
}
function check_form()
{
	var form = document.forms['page_form'];
	form.added_img.value = global_uploaded_image.join(',');
	form.submit();
	return false;
}
</script>
<title>班尼頓寫真後台管理</title>
</head>

<body>
<?php include_once('admin-top.php');?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" name="page_form"> 
<input type="hidden" name="working_id" value="<?php echo $_REQUEST['working_id'];?>"/>
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="added_img" value=""/>
<div id="main" class="clearfix"><!-- star #main //-->
  <?php include_once('sub-working.php');?>
  <div id="contactall"><!-- star #main //-->
  <div id="tit" ><!-- star #tit //-->
    <ul>
    <li class="tit-a">管理相簿</li>
    <li class="tit-b"><a href="#" onclick="javascript:edit_toa(1118);return false;">新增 </a> <a href="#save" onclick="return check_form();">儲存</a></li>
    </ul>
  </div><!-- end #tit //-->
  <div id="PhotoList" class="clearfix" ><!-- star #contactEdit //-->
  <?php foreach($GLOBALS['PAGE_LIST_DATA'] as $row):?>
    <?php 
     	$img_disk_path = constant('SITE_WEB_DISK_DIR').'/img/'.$GLOBALS['GV_IMAGE_PATH'].$row['path'];
     	$i_with = 300;
     	$i_height = 200;
     	list($src_width, $src_height, $type, $attr) = getimagesize($img_disk_path);
     	if ( $src_width < $src_height) {
     		$tmp = $i_with;
     		$i_with = $i_height;
     		$i_height = $tmp;
     	}
     ?>
  <ul>
    <li class="photo-indexa">
    <img id="img_image_<?php echo $row['id'];?>" src="../img/<?php echo $GLOBALS['GV_IMAGE_PATH'].$row['path'];?>" width="<?php echo $i_with;?>" height="<?php echo $i_height;?>" />
    </li>
    <li class="pl-1"><a href="#del">刪除</a></li>
    <li class="pl-1">
    <input id="image_<?php echo $row['id'];?>" type="file" name="image_<?php echo $row['id'];?>" class="uploadifyupload"/>
     <input name="ajaxf_image_<?php echo $row['id'];?>" type="hidden"/>
    </li>
   </ul>
  <?php endforeach;?>
  </div><!-- end #contactEdit //-->
  
  </div><!-- end #contactall //-->
</div><!-- end #main //-->
</form>
</body>
</html>